-- UIBlackMask
-- Created by chendh
-- 黑色蒙版界面

UIBlackMask = class("UIBlackMask", function()
    return cc.Layer:create();
end);

function UIBlackMask.create(duration, callback, zOrder)
    return UIBlackMask.new(duration, callback, zOrder);
end

-- 构造函数
function UIBlackMask:ctor(duration, callback, zOrder)
    self:setName("UIBlackMask");
    local node = cc.CSLoader:createNode("layout/common/BlackMask.csb");
    self:addChild(node);
    self.node = node;

    zOrder = zOrder or UIMgr.TOP_MENU_ZORDER + 100000;
    self:setLocalZOrder(zOrder);

    self:resize();

	-- duration秒后自动关闭
	local function close()
		UIMgr.getCurrentScene():removeForm(self);

		if callback then
		  callback();
		end
	end

	if duration ~= nil then
	   performWithDelay(self, close, duration);
	end
end

-- 适配
function UIBlackMask:resize()
    local w = cc.Director:getInstance():getOpenGLView():getFrameSize().width;
    local h = cc.Director:getInstance():getOpenGLView():getFrameSize().height;
    local node = self.node;

    local blackMask = findChildByName(node, "black_mask");
    blackMask:setPosition(w / 2, h / 2);
    blackMask:setContentSize(w, h);
    self.blackMask = blackMask;
end




